package com.nullpointer.xchatfinal.object;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class DetailedMessage {
	private String targetID;// to group? to other user
	private String targetName;
	private MessageContent messageContent;
	private long createAt;

	public long getCreateAt() {
		return createAt;
	}

	public void setCreateAt(long createAt) {
		this.createAt = createAt;
	}

	public String getTargetID() {
		return targetID;
	}

	public void setTargetID(String targetID) {
		this.targetID = targetID;
	}

	public String getTargetName() {
		return targetName;
	}

	public void setTargetName(String targetName) {
		this.targetName = targetName;
	}

	public MessageContent getMessageContent() {
		return messageContent;
	}

	public void setMessageContent(MessageContent messageContent) {
		this.messageContent = messageContent;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static DetailedMessage fromJsonToDetailedMessage(String json) {
		return new JSONDeserializer<DetailedMessage>().use(null,
				DetailedMessage.class).deserialize(json);
	}

	public static String toJsonArray(Collection<DetailedMessage> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

	public static Collection<DetailedMessage> fromJsonArrayToDetailedMessages(
			String json) {
		return new JSONDeserializer<List<DetailedMessage>>()
				.use(null, ArrayList.class)
				.use("values", DetailedMessage.class).deserialize(json);
	}

}
